<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue生命周期</title>
    <script src="/js/vue-2.7.9-dev.js"></script>
    <style>
    </style>
    
</head>
<body>
    <div id="app">
        <h2 :style="{opacity}">看笔记学Vue</h2>

        <div id="num">{{num}}</div>
        <button @click="num++">click me</button>
        <button @click="destroyVue">destroy</button>
        <button onclick="aa()" id="btn">原生事件</button>
    </div>

    <script>
        let btn = document.getElementById("btn")
        console.log(btn);
        function aa(){
            alert("我是原生注册的事件")
        }
        let vm = new Vue({
            data() { 
                console.log("==", this);
                return { 
                    num:0,
                    opacity:1
                }
            },
            beforeCreate() {
                console.log('beforeCreate', this)
            },
            created() {
                console.log('created', this)
            },
            beforeMount() {
                console.log('beforeMount', this)
            },
            mounted() {
                console.log('mounted', this.num)
                
                // setInterval(() => {
                //     this.opacity -= 0.01
                //     if(this.opacity <= 0) this.opacity = 1
                // }, 16)
            },
            beforeUpdate() {
                console.log('beforeUpdate', this.num)
                // 获取dom中的数组
                let oldNum = document.getElementById("num").innerHTML
                console.log("更新之前的数据是", oldNum);
            },
            updated() {
                console.log('updated', this, this.num)
                let oldNum = document.getElementById("num").innerHTML
                console.log("更新之后的数据是", oldNum);
            },
            beforeDestroy() {
                console.log('beforeDestroy', this)
            },
            destroyed() {
                console.log('destroyed', this)
            },
            methods: {
                destroyVue(){
                    this.$destroy()
                }
            },
        })
        vm.$mount("#app")
        console.log("--",vm);
    </script>
</body>
</html>